const router = require("koa-router")();
router.get("/recommend", async (ctx, next) => {
  let arr = [];
  for (let i = 0; i < 50; i++) {//
    // 生成1-73281之间的随机整数
    const randomNum = Math.floor(Math.random() * 73281) + 1;
    let sql = `select * from chinesepoetry where poetryId like '${randomNum}'`;
    let result = await ctx.db.EXCUTE(sql);
    arr.push(result);
  }
  ctx.body = arr;
  arr = [];
});
router.get("/flash", async (ctx, next) => {
  let arr = "";
  // 生成1-73281之间的随机整数
  const randomNum = Math.floor(Math.random() * 73281) + 1;
  let sql = `select * from chinesepoetry where poetryId like '%${randomNum}%'`;
  let result = await ctx.db.EXCUTE(sql);
  arr = result;
  ctx.body = arr;
  arr = "";
});

router.post('/getdetails', async(ctx, next) => {
  console.log(ctx.request.body);
  let sql = `SELECT * FROM chinesepoetry WHERE name like "${ctx.request.body.id}" and author like "${ctx.request.body.author}%"`  
  let result = await ctx.db.EXCUTE(sql);
  console.log(result);
  ctx.body = result
})

module.exports = router;
